package net.jdm.domain.entity;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.jdm.domain.dependence.ClassDependence.ClassDependType;
public class Class implements Node{
    private String name;
    private String packageName = "default";
    private boolean beAbstract= false;
    private String sourceFile= "Unknown";
    Map<ClassDependType,Set<Class>> dependClasses=new HashMap<ClassDependType,Set<Class>>();
	public Class(String name) {
		this.name = name;
	}
	@Override
	public String getName() {
		return this.name;
	}
	public Map<ClassDependType,Set<Class>> getDependClassesWithType() {
		return this.dependClasses;
	}
	public Set<Class> getDependClasses() {
		Set<Class> result=new HashSet<Class>();
		for(Set<Class> classes:this.dependClasses.values()){
			result.addAll(classes);
		}
		return result;
	}
	public void dependUpon(ClassDependType type,Class dependClass) {
		if(dependClass==null||this.equals(dependClass))
			return;
		Set<Class> depends= this.dependClasses.get(type);
		if(depends==null){
			depends=new HashSet<Class>();
			this.dependClasses.put(type, depends);
		}
		depends.add(dependClass);
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}
	public String getPackageName() {
		return packageName;
	}
	public void setAbstract(boolean isAbstract) {
		this.beAbstract = isAbstract;
	}
	public boolean isAbstract() {
		return beAbstract;
	}
	public void setSourceFile(String sourceFile) {
		this.sourceFile = sourceFile;
	}
	public String getSourceFile() {
		return sourceFile;
	}
	@Override
	public boolean equals(Object other){
        if (other!=null&&other.getClass().equals(this.getClass())) {
        	Class otherClass = (Class) other;
            return otherClass.getName().equals(getName());
        }
        return false;
	}
	@Override
    public int hashCode() {
        return toString().hashCode();
    }
	@Override
	public String toString(){
		return getName();
	}
}
